#include "model/mixin/limits.h"

Limits::Limits() {
    this->resetLimits();
}

coord Limits::width() const {
    return greater.x - greater.y;
}

coord Limits::height() const {
    return greater.y - greater.y;
}

Vertex Limits::center() const {
    return (lower+greater)*0.5;
}

void Limits::updateLimits(const Vertex &vertex) {
    if ( vertex.x < lower.x )
        lower.x = vertex.x;
    else if ( vertex.x > greater.x )
        greater.x = vertex.x;

    if ( vertex.y < lower.y )
        lower.y = vertex.y;
    else if ( vertex.y > greater.y )
        greater.y = vertex.y;

    if ( vertex.z < lower.z )
        lower.z = vertex.z;
    else if ( vertex.z > greater.z )
        greater.z = vertex.z;
}

void Limits::resetLimits() {
    this->lower = Vertex::max();
    this->greater = Vertex::min();
}



